package org.example.com.service.impl;

import org.example.com.pojo.ServiceConfig;
import org.example.com.mapper.ServiceConfigMapper;
import org.example.com.service.ServiceConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ServiceConfigServiceImpl implements ServiceConfigService {

    @Autowired
    private ServiceConfigMapper serviceConfigMapper;

    @Override
    public List<ServiceConfig> getServiceConfigsByType(String configType) {
        return serviceConfigMapper.findByConfigType(configType);
    }

    @Override
    public List<ServiceConfig> getActiveServiceConfigs() {
        return serviceConfigMapper.findActiveConfigs();
    }

    @Override
    public ServiceConfig getServiceConfigById(Integer id) {
        return serviceConfigMapper.findById(id);
    }

    @Override
    @Transactional
    public boolean createServiceConfig(ServiceConfig serviceConfig) {
        return serviceConfigMapper.insert(serviceConfig) > 0;
    }

    @Override
    @Transactional
    public boolean updateServiceConfig(ServiceConfig serviceConfig) {
        return serviceConfigMapper.update(serviceConfig) > 0;
    }

    @Override
    @Transactional
    public boolean deleteServiceConfig(Integer id) {
        return serviceConfigMapper.deleteById(id) > 0;
    }
}
